import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import dao.UserDaoImpl;
import org.junit.Test;
import pojo.User;

import java.sql.SQLException;
import java.util.List;

public class Mytest {
    @Test
    public  void test1() throws SQLException {
        UserDaoImpl userDao = new UserDaoImpl();
        User zhouying = userDao.selectByUsername("zhouying");
        System.out.println(zhouying);
        //对象转JSON
        String s = JSON.toJSONString(zhouying);
        System.out.println(s);
        //Json转对象
        User user = JSON.parseObject(s,User.class);
        System.out.println(user);
        //对象集合转JSON
        List<User> users = userDao.selectAll();
        String s1 = JSON.toJSONString(users);
        System.out.println(s1);
        //JSON转对象集合
        List<User> users1 = JSON.parseArray(s1, User.class);
        for (User user1 : users1) {
            System.out.println(user1);
        }
    }
}
